<template>
	<view class="yp" :class="{'theme--Black':CurrentTheme.name==='DarkMode'}">
		<app-headers></app-headers>
		<!-- 分享、设置按钮 -->
		<headers></headers>
		<!-- 头像、信息 -->
		<info :UserInfo="UserInfo" :CurrentSize.number()='CurrentSize'></info>
		<!-- 网盘功能 -->
		<fn-block></fn-block>
		<!-- 操作条 -->
		<operate-bar></operate-bar>
		<!-- 退出登录 -->
		<login-out></login-out>
	</view>
</template>

<script>
	import headers from './header/index.vue';
	import info from './info/index.vue';
	import FnBlock from './FnBlock/index.vue';
	import OperateBar from './OperateBar/index.vue';
	import LoginOut from './LoginOut/index.vue';
	import {
		API$GetUserinfo
	} from '../../common/API/home.js';
	import {
		API$getSpecifiedFileSizes
	} from '../../common/API/file.js';
	export default {
		name: '',
		components: {
			headers,
			info,
			FnBlock,
			OperateBar,
			LoginOut
		},
		data() {
			return {
				UserInfo: {}, // 用户信息
				CurrentSize: 0, // 该用户的总空间
			};
		},
		onShow() {
			// #ifdef APP-PLUS
			//设置导航栏前景色
			this.$nextTick(()=>plus.navigator.setStatusBarStyle(this.CurrentTheme.name==='DarkMode'?'light':"dark"))
			// #endif
			if (this.$pub.getStorageSync('UserInfo')) {
				this.UserInfo.Nickname = uni.getStorageSync('UserInfo').Nickname || '暂未设置';
				this.UserInfo.avatar = uni.getStorageSync('UserInfo').avatar ||
					'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg';
				this.UserInfo.UserStorageSpace = uni.getStorageSync('UserInfo').UserStorageSpace || 0;
					
				this.getSpecifiedFileSizes(this.$pub.getStorageSync('UserInfo').account)
			}
		},
		onReady() {
			this.GetUserInfo();
		},
		methods: {
			/*********************************************数据处理部分**************************************************************/
			async GetUserInfo(json) {
				try {
					uni.showLoading({
						mask: true
					});
					let res = await API$GetUserinfo(json);
					if (res.code == 200) {
						this.$pub.setStorageSync('UserInfo', res.result);
						this.UserInfo = res.result;

						this.UserInfo.avatar = res.result.avatar ? res.result.avatar :
							'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg';
						this.UserInfo.Nickname = res.result.Nickname ? res.result.Nickname : '暂未设置';

						this.getSpecifiedFileSizes(this.$pub.getStorageSync('UserInfo').account)
					}
				} catch (e) {
					console.log(e);
				} finally {
					uni.hideLoading();
				}
			},
			// 获取用户的免费存储空间大小
			async getSpecifiedFileSizes(account) {
				let {
					code,
					msg,
					data
				} = await API$getSpecifiedFileSizes({
					account
				})
				if (code === 200) {
					this.CurrentSize = data.CurrentSize
				}
			}
		}
	};
</script>

<style lang="less" scoped>
	.yp {
		/* #ifdef H5 */
		height: calc(100vh - 50px);
		/* #endif */
		/* #ifdef APP-PLUS */
		height: calc(100vh);
		/* #endif */
		overflow: scroll;
	}
	.theme--Black{
		/deep/ .yz .list .list-item{
			color: #ffffff;
		}
		/deep/ .icon-circle{
			background-color: #000000;
			color:#ffffff;
		}
	}
	
</style>
